package ACM.zijie;

import java.util.Scanner;

/**
 * @Author wwk
 * @DATE 2022/8/28 10:57
 */
import java.util.*;

public class forth {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        System.out.println(maxSum(n,k,arr));
    }

    public static long maxSum(int n,int k,int arr[]) {
        k++;
        PriorityQueue<int[]> pq = new PriorityQueue<>(
                (o1,o2) -> {
                    return o1[0] - o2[0];
                }
        );
        long sum = 0;
        for (int i = 0; i < k; i++) {
            pq.add(new int[]{arr[i],i});
            sum += arr[i];
        }
        long ans = sum - pq.peek()[0];
        for(int i = k; i < n; i++){
            sum += arr[i];
            sum -= arr[i-k];
            while(pq.peek()[1]<=i-k) pq.poll();
            ans = Math.max(ans,sum-pq.peek()[0]);
        }
        return ans;
    }
}
